package tms.persistence.login;

import tms.model.login.UserEntity;
import tms.persistence.ProviderBase;

import javax.ejb.Local;
import javax.ejb.Stateless;
import java.util.List;

@Local
@Stateless
public class LoginProvider extends ProviderBase {

    public void createUser(UserEntity user) {
        getEntityManager().persist(user);
    }

    @SuppressWarnings("unchecked")
    public List<UserEntity> getUsersByName(String name) {
        return getEntityManager().createNamedQuery("UserEntity.getByName").setParameter("name", name).getResultList();
    }

    public UserEntity findUser(Integer id) {
        return getEntityManager().find(UserEntity.class, id);
    }

    @SuppressWarnings("unchecked")
    public List<UserEntity> getAllUsers() {
        return getEntityManager().createNamedQuery("UserEntity.getAll").getResultList();
    }
}
